from django.db import models

# Create your models here.
# 创建图书模型类，继承Model类
class Book(models.Model):
    # 添加属性，最后映射为字段，需要指定类型
    title = models.CharField('书名', max_length=32, unique=True, default='')
    pub = models.CharField('出版社', max_length=100, null=False, default='')
    price = models.DecimalField('价格', max_digits=7, decimal_places=2, default=0)
    market_price = models.DecimalField('图书零售价', max_digits=7, decimal_places=2, default=0)
    # 是否显示
    is_active = models.BooleanField('是否活跃', default=True)
    def __str__(self):
        return f'{self.title}, {self.pub}, {self.price}, {self.market_price}'
    class Meta:
        db_table = 'book' # 修改生成的表名称
        verbose_name = '图书'  # 修改Admin站点中的名称（单数）
        verbose_name_plural = verbose_name  # 复数名称
# 作家模型类
class Author(models.Model):
    name = models.CharField('姓名', max_length=11, null=False, default='')
    age = models.IntegerField('年龄', default=1)
    email = models.EmailField('邮箱', null=True, default='')
    class Meta:
        db_table = 'author'
        verbose_name = '作家'
        verbose_name_plural = verbose_name

